package com.huajin.codetest.thread.pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorTest {
	
	public static void main1(String[] args) {
		ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(20, 30, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
		for (int i = 0; i < 5000; i++) {
			threadPoolExecutor.execute(() -> {
				System.out.println("execute：" + threadPoolExecutor.getCorePoolSize());
				System.out.println("execute：" + threadPoolExecutor.getPoolSize());
				System.out.println("execute：" + threadPoolExecutor.getQueue().size());
				try {
					System.out.println("business：" + Thread.currentThread().getName());
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			});
		}
		System.out.println(threadPoolExecutor.getCorePoolSize());
		System.out.println(threadPoolExecutor.getPoolSize());
		System.out.println(threadPoolExecutor.getQueue().size());
	}
	
	public static void main(String[] args) {
		ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 30, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
		for (int i = 0; i < 10; i++) {
			threadPoolExecutor.execute(() -> {
				System.out.println("execute：" + threadPoolExecutor.getCorePoolSize());
				System.out.println("execute：" + threadPoolExecutor.getPoolSize());
				System.out.println("execute：" + threadPoolExecutor.getQueue().size());
				for (int j = 0; j < 500; j++) {
					try {
						System.out.println("business：" + Thread.currentThread().getName());
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			});
		}
		System.out.println(threadPoolExecutor.getCorePoolSize());
		System.out.println(threadPoolExecutor.getPoolSize());
		System.out.println(threadPoolExecutor.getQueue().size());
	}

}
